package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizProfileSource;
import com.member.shop.service.ISysBizProfileSourceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【资料库资源】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-05-08
 **/
@RestController
@RequestMapping("/shop/source")
public class SysBizProfileSourceController extends BaseController {
    @Resource
    private ISysBizProfileSourceService sysBizProfileSourceService;

    /**
     * 查询资料库资源列表
     */
    @PreAuthorize("@ss.hasPermi('shop:source:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizProfileSource sysBizProfileSource) {
        startPage();
        LambdaQueryWrapper<SysBizProfileSource> queryWrapper = new LambdaQueryWrapper<SysBizProfileSource>();
        List<SysBizProfileSource> list = sysBizProfileSourceService.selectSysBizProfileSourceList(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出资料库资源列表
     */
    @PreAuthorize("@ss.hasPermi('shop:source:export')")
    @Log(title = "资料库资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizProfileSource sysBizProfileSource) {
        LambdaQueryWrapper<SysBizProfileSource> queryWrapper = new LambdaQueryWrapper<SysBizProfileSource>();
        List<SysBizProfileSource> list = sysBizProfileSourceService.selectSysBizProfileSourceList(queryWrapper);
        ExcelUtil<SysBizProfileSource> util = new ExcelUtil<SysBizProfileSource>(SysBizProfileSource.class);
        util.exportExcel(response, list, "资料库资源数据");
    }

    /**
     * 获取资料库资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:source:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizProfileSourceService.selectSysBizProfileSourceById(id));
    }

    /**
     * 新增资料库资源
     */
    @PreAuthorize("@ss.hasPermi('shop:source:add')")
    @Log(title = "资料库资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizProfileSource sysBizProfileSource) {
        return toAjax(sysBizProfileSourceService.insertSysBizProfileSource(sysBizProfileSource));
    }

    /**
     * 修改资料库资源
     */
    @PreAuthorize("@ss.hasPermi('shop:source:edit')")
    @Log(title = "资料库资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizProfileSource sysBizProfileSource) {
        return toAjax(sysBizProfileSourceService.updateSysBizProfileSource(sysBizProfileSource));
    }

    /**
     * 删除资料库资源
     */
    @PreAuthorize("@ss.hasPermi('shop:source:remove')")
    @Log(title = "资料库资源", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizProfileSourceService.deleteSysBizProfileSourceByIds(ids));
    }
}
